<?php
/**
 * Created by litong on Date: 2019/2/24 0024 下午 9:32
 */
$host="localhost";$username="root";$password="";$dbname="php_study";
$sql = "INSERT INTO my_guests (firstname, lastname, email) VALUES ('John', 'Doe', 'john@example.com')";
try{
  $connection = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
  $connection->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
  $connection->exec($sql);
  echo "执行成功";
}catch (PDOException $e){
  echo $e->getMessage();
}